package com.atguigu.flink.chapter02_DataStreamAPI.simpletrans;

import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * Created by Smexy on 2022/10/22
 */
public class Demo7_Filter
{
    public static void main(String[] args) {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<Integer> source = env.fromElements(1, 2, 3,4,5,6,7);

        source
            .filter(new FilterFunction<Integer>()
            {
                //默认留下返回值为true，将不为true过滤掉
                @Override
                public boolean filter(Integer value) throws Exception {
                    return (value % 2) == 1 ;
                }
            })
            .print();

        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
